package com.cebbank.yyi.springbootapp.poi;

import org.apache.poi.ss.usermodel.*;

/**
 * @description:
 * @author: yyi
 * @version: 1.0
 **/

public class CustomerHandler implements ExcelHandlerAdapter {

    @Override
    public Object format(Object value, String[] args, Cell cell, Workbook workbook) {
        if (String.valueOf(value).equals("1")) {
            // 自定义用户名为若依/单元格文字设置为红色
            CellStyle style = workbook.createCellStyle();
            style.setAlignment(HorizontalAlignment.CENTER);
            style.setVerticalAlignment(VerticalAlignment.CENTER);
            style.setBorderRight(BorderStyle.THIN);
            style.setRightBorderColor(IndexedColors.GREY_50_PERCENT.getIndex());
            style.setBorderLeft(BorderStyle.THIN);
            style.setLeftBorderColor(IndexedColors.GREY_50_PERCENT.getIndex());
            style.setBorderTop(BorderStyle.THIN);
            style.setTopBorderColor(IndexedColors.GREY_50_PERCENT.getIndex());
            style.setBorderBottom(BorderStyle.THIN);
            style.setBottomBorderColor(IndexedColors.GREY_50_PERCENT.getIndex());
            style.setFillBackgroundColor(IndexedColors.BLUE.getIndex());
            style.setFillPattern(FillPatternType.SOLID_FOREGROUND);
            Font dataFont = workbook.createFont();
            dataFont.setFontName("Arial");
            dataFont.setFontHeightInPoints((short) 10);
            dataFont.setColor(IndexedColors.RED.index);
            style.setFont(dataFont);
            cell.setCellStyle(style);
        }
        return value;
    }

    @Override
    public Object format(Object value, String[] args) {
        return value;
    }
}
